package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {
    /**
     *  根据分类id查询套餐
     * @param categoryId
     * @return
     */
    @Select("select * from setmeal where category_id = #{categoryId}")
    List<Setmeal> getByCategoryId(Long categoryId);

    /**
     *  分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    List<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     *  新增套餐
     * @param setmeal
     */
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into setmeal (category_id, name, price, status, description, image, create_time, update_time, create_user, update_user) " +
            "values" +
            " (#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser}) " )
    void insert(Setmeal setmeal);

    /**
     *  根据id查询套餐
     * @param id
     * @return
     */
    @Select("select s.* ,c.name as categoryName " +
            "from setmeal s left join category c on s.category_id = c.id " +
            "where s.id = #{id}")
    SetmealVO getById(Long id);

    /**
     *  修改套餐
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     *  根据id批量查询套餐的状态
     * @param ids
     * @param status
     * @return
     */
    Long getStatusById(List<Long> ids, Integer status);

    /**
     *  根据id批量删除套餐
     * @param ids
     */
    void deleteByIds(List<Long> ids);
}
